
 /*-------------------------------------------------------------------

                 KEYBOARD   INTERRUPT   HANDLER

           This program is memory resident and toggles the state
       of the capslock when the keys CTRL and ALT are pressed
       simultaneously.
           The previous state of the keyboard flags is known from
       the keyboard flag byte, which is stored at 0000:0417 in the
       memory. If the current state is LOWER CASE, then it is
       converted to UPPER CASE and VICE VERSA. The appropriate values
       are poked into the byte.

           The keyboard flags byte is as follows :

         7      6      5      4      3      2      1      0
      +------+------+------+------+------+------+------+------+
      |Insert| Caps | Num  |Scroll| Alt  | Ctrl | Left |Right |
      |Lock  | Lock | Lock |Lock  | Key  | Key  | Shift|Shift |
      +------+------+------+------+------+------+------+------+

 -------------------------------------------------------------------*/

 # include <stdio.h>
 # include <dos.h>

 # define LOWER  0
 # define UPPER  1

 void interrupt (*oldkey) () ;

 struct shftkey {
                  unsigned Rshift : 1 ;
                  unsigned Lshift : 1 ;
                  unsigned Ctrl   : 1 ;
                  unsigned Alt    : 1 ;
                  unsigned Scroll : 1 ;
                  unsigned Num    : 1 ;
                  unsigned Caps   : 1 ;
                  unsigned Insert : 1 ;
                 } ;

 struct shftkey huge *shft ;

 int current_case = LOWER ;

 void change_current_case()
  {
    if ( current_case == LOWER )
     {
       pokeb(0x0000,0x0417,0x40) ;
       current_case = UPPER ;
      }
    else
      {
        pokeb(0x0000,0x0417,0) ;
        current_case = LOWER ;
       }
   }

 void interrupt off()
  {
    char c ;

    (*oldkey) () ;
    enable() ;
    if ( ( shft -> Ctrl ) && ( shft -> Alt ) )
      change_current_case() ;
   }

 main()
  {
    unsigned mem = (5065/16) + 1 ;

    pokeb(0x0000,0x0417,0x00) ;

    shft = (struct shftkey huge *) 0x417 ;
    oldkey = getvect(0x9) ;
    setvect(0x9,off) ;
    keep(0,mem) ;
   }
